<?php

namespace app\api\controller;

use app\common\controller\Api;
use app\common\library\Sms;

/**
 * Class RankCard
 * @package app\api\controller
 * 银行卡
 */
class RankCard extends Api
{
    protected $noNeedLogin = [];
    protected $noNeedRight = [];

    public function index(){
        $rankCard = new \app\admin\model\RankCard();
        $uid = $this->uid;
        $list = $rankCard->field('id,type,num,mobile,cardholder')->where(['uid'=>$uid])->find();
        $this->ajaxSuccess($list);
    }

    /*
     * 绑定银行卡
     */
    public function addRankcard(){
        $ret = Sms::check(input('mobile'), input('code'), 'bindBankCard');
        if (!$ret) {
            $this->ajaxError('验证码错误');
        }
        $data['uid'] = $this->uid;
        $data['type'] = input('type');
        $data['num'] = input('num');
        $data['mobile'] = input('mobile');
        $data['cardholder'] = input('cardholder');
        if(!empty(input('cid'))){
            $data['update_time'] = time();
            db('rank_card')->where('id',input('cid'))->update($data);
        }
        $data['create_time'] = time();
        $result = db('rank_card')->insert($data);
        if ($result){
            $this->ajaxSuccess();
        }

    }


}
